package com.ewanghuiju.app.ui.my.activity;

import android.view.View;
import android.widget.RelativeLayout;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.main.InterestTagContract;
import com.ewanghuiju.app.model.bean.response.IntenestTagResponBean;
import com.ewanghuiju.app.presenter.main.InterestTagPresenter;
import com.ewanghuiju.app.test.bean.TestBean;
import com.ewanghuiju.app.ui.main.adapter.MyFlowTagAdapter;
import com.gyf.immersionbar.ImmersionBar;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author sj  qq:751943509
 * @class 购物喜好页面
 * @time 2020/2/14
 */
public class ShopPreferencesActivity extends BaseActivity<InterestTagPresenter> implements InterestTagContract.View {

    @BindView(R.id.toolbar)
    RelativeLayout toolbar;
    @BindView(R.id.flowLayout_select)
    TagFlowLayout flowLayoutSelect;
    @BindView(R.id.flowLayout_unselect)
    TagFlowLayout flowLayoutUnselect;

    private  List<IntenestTagResponBean> unSelectedList;
    private  List<IntenestTagResponBean> selectedList;

    private  MyFlowTagAdapter myUnSelectedFlowTagAdapter;
    private  MyFlowTagAdapter mySelectedFlowTagAdapter;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_shop_preferences;
    }

    @Override
    protected void initEventAndData() {
        initTag();
    }

    private void initTag() {
        selectedList = new ArrayList<>();
        unSelectedList = TestBean.getIntenestTagResponBeanList();

        //选中
        mySelectedFlowTagAdapter = new MyFlowTagAdapter(selectedList, mContext,1);
        flowLayoutSelect.setAdapter(mySelectedFlowTagAdapter);
        flowLayoutSelect.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
//                int status = unSelectedList.get(position).getStatus();
//                unSelectedList.get(position).setStatus(status == 0 ? 1 : 0);
                IntenestTagResponBean  itbean =  selectedList.get(position);
                for (IntenestTagResponBean it:unSelectedList){
                    if(itbean.getId()==it.getId()){
                        it.setStatus(0);
                        it.setType(0);
                    }
                }
                selectedList.remove(position);
                myUnSelectedFlowTagAdapter.notifyDataChanged();
                mySelectedFlowTagAdapter.notifyDataChanged();
                return true;
            }
        });


        //未选中
        myUnSelectedFlowTagAdapter = new MyFlowTagAdapter(unSelectedList, mContext,0);
        flowLayoutUnselect.setAdapter(myUnSelectedFlowTagAdapter);
        flowLayoutUnselect.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
//                int status = unSelectedList.get(position).getStatus();
//                unSelectedList.get(position).setStatus(status == 0 ? 1 : 0);
                IntenestTagResponBean  itbean =  unSelectedList.get(position);
                itbean.setStatus(1);
                itbean.setType(1);
                selectedList.add(itbean);
                myUnSelectedFlowTagAdapter.notifyDataChanged();
                mySelectedFlowTagAdapter.notifyDataChanged();
                return true;
            }
        });
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(toolbar, true)
                .transparentBar()
                .statusBarDarkFont(true)
                .navigationBarDarkIcon(true)
                .init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }
}
